import { User } from '../database/database'
import Sequelize from 'sequelize'
const Op = Sequelize.Op
export default {
    save : async(user) => {
        await User.upsert(user)
    },
    get : async(id) =>{
        return await User.findById(id)
    },
    getByCode : async(code) =>{
        return await User.findOne({
            where: {
                code:code
            }
        })
    },
    findNoBuys : async() =>{
        let date1 = new Date().getTime() - (30 * 60 * 1000)
        let date2 = new Date().getTime() - (60 * 60 * 1000)
        return await User.findAll({
            where: {
                status : 0,
                send : 0,
                createdAt: {
                    [Op.lte]: date1,
                    [Op.gte]: date2
                }
            }
        })
    }
}